<?php

namespace Org\Net;

/**
 * function 函数库
 * 自定义基础函数库
 */
class Fun {
    
    /**
     * 带域名参数的URL拼接
     * @param type $url
     * @return type
     */
    static public function url($url = '/admin/index/test',$arr = array()) {
        $baseUrl = "http://".$_SERVER['SERVER_NAME'];
        if ($url) {
            $repoUrl = U($url,$arr);
        }
        return $baseUrl . $repoUrl;
    }
    
    /**
     * 返回时间戳
     * @return type
     */
    static public function now_time() {
       return time();
    }
	
	
	/**
	 * 生成一串数字
	 */
	static public function randNumber($long = 15){
		$arr = array();
		for($i=0;$i<$long;$i++){
			$arr[] = rand(1,9);
		}
		$arrStr = implode("", $arr);
		return $arrStr;
	}
    
    
    
    static public function data_to_table($header, $data, $file_name, $coding = 'utf-8') {
        header("Content-type:application/vnd.ms-excel;charset:$coding");
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename="' . $file_name . '.xls"');
        header("Content-Transfer-Encoding:binary");
        foreach ($header as $val) {
            $str_header .= "<th>$val</th>";
        }
        $output = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
                            xmlns:x="urn:schemas-microsoft-com:office:excel"
                            xmlns="http://www.w3.org/TR/REC-html40">
                            <html xmlns="http://www.w3.org/1999/xhtml">
                             <head>
                              <title>' . $header . '</title>
                              <meta http-equiv="Content-Type" content="text/html; charset=' . $coding . '"/>

                             </head>
                             <body>
                            <style>
                            th {background:#f0f0f0}
                            td {font-size:10.0pt;}
                            </style>
                            <table cellspacing="1" cellpadding="5" borderColorDark="#ffffff" width="100%"
                            bgColor="#ffffff" borderColorLight="#c0c0c0" border="1">
                                    <tr>
                                            ' . $str_header . '
                                    </tr>
                            ';
        foreach ($data as $row) {
            $output .= "<tr>\n";
            foreach ($row as $field) {
                $output .= "<td>{$field}</td>";
            }
            $output .= "</tr>\n";
        }
        $output .= "</table>\n";
        $output .= '</body></html>';
        exit($output);
    }
	
	
	
    
}
